﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WL_Store.BLL;
using WL_Store.Model;

namespace WL_Store.Web.subpage
{
    public partial class administrator_edit : System.Web.UI.Page
    {
        EmployeeInfoBLL bll = new EmployeeInfoBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindPerList();
                string  ID = Request.QueryString["number"].ToString();
                EmployeeInfoModel model = bll.employee(ID);
                if (model != null)
                {
                    this.txt_edit_name.Text = model.name;
                    this.txt_edit_age.Text = model.age.ToString();
                    this.txt_edit_idcard.Text = model.idcard;
                    this.txt_edit_phone.Text = model.phone;
                    this.txt_edit_email.Text = model.email;
                    this.txt_edit_adress.Text = model.address;
                    this.ddl_edit_jibie.SelectedValue = model.GradeId.ToString();
                    this.rbl_edit_sex.SelectedValue = model.sex ? "1" : "0";

                }

            }

              

                
                //Page.ClientScript.RegisterStartupScript(this.GetType(), "addclass", "<script> $('.administrator_edit').on('click', function () { layer.open({ type: 1, title: '编辑管理员', area: ['700px', ''],shadeClose: false, content: $('#edit_administrator_style'), }); })</script");
            
            
        }
        private void BindPerList()
        {
            EmployeeInfoBLL eb = new EmployeeInfoBLL();
            //读取权限信息
            DataTable dd = eb.PermissionInfo();
            //数据源赋值
           
            ddl_edit_jibie.DataSource = dd;
            //显示字段
            
             ddl_edit_jibie.DataTextField = "Grade";
            //值字段
            
            ddl_edit_jibie.DataValueField = "GradeId";
            //绑定
           
            ddl_edit_jibie.DataBind();
            //ddl_edit_jibie.Items.Insert(0, new ListItem("全部", "0"));
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                //获取用户填写的信息
                string name= this.txt_edit_name.Text.Trim();
                int sex = Convert.ToInt32(this.rbl_edit_sex.SelectedValue);
                string age = this.txt_edit_age.Text.Trim();
                string GradeId = this.ddl_edit_jibie.SelectedValue;
                string idcard = this.txt_edit_idcard.Text.Trim();
                string phone = this.txt_edit_phone.Text.Trim();
                string email = this.txt_edit_email.Text.Trim();
                string address = this.txt_edit_adress.Text.Trim();

                string ID =Request.QueryString["number"];
                EmployeeInfoModel model = new EmployeeInfoModel();
                model.name = name;
                model.sex = Convert.ToBoolean(sex);
                model.age = Convert.ToInt32(age);
                model.GradeId = Convert.ToInt32(GradeId);
                model.idcard = idcard;
                model.phone = phone;
                model.email = email;
                model.address = address;
                model.number = ID;


                if (bll.UpdateemployeeProc(model))
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(),"alert", "<script> parent.layer.msg('修改成功！', { time: 1000, shade: 0.3 },function(){parent.layer.close(parent.layer.getFrameIndex(window.name));})</script>") ;
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('修改失败！')</script>");
                }
            }
        }
    }
}